#include <string.h>

#include "../config.h"
#include "main.h"

#include "logwin.h"

GtkWidget *confwin;
GtkWidget *conf_optisochooser;
s8 opened = 0;

void confwin_init(GtkBuilder *builder)
{
    char *path;
    /* the confing window */
    confwin = GTK_WIDGET(gtk_builder_get_object(builder, "confwin"));

    /* the ISO path selector */
    conf_optisochooser = GTK_WIDGET(gtk_builder_get_object(builder, "conf_optisochooser"));
    path = conf_load("isopath");
    if (path) {
        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(conf_optisochooser), path);
        conf_free(path);
    }

    gtk_widget_hide_all(confwin);
}

G_MODULE_EXPORT void confwin_open()
{
    if (!opened)
        gtk_widget_show_all(confwin);
    opened = 1;
}

void confwin_close()
{
    gtk_widget_hide(confwin);
    opened = 0;
}

G_MODULE_EXPORT void confwin_save()
{
    gchar *path;
    confwin_close();
    path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(conf_optisochooser));
    gdk_threads_leave();
    conf_save("isopath", path);
    gdk_threads_enter();
    gameslist_sync();
}

G_MODULE_EXPORT void confwin_cancel()
{
    confwin_close();
}

